#
#   Python GUI - Drawing - Generic
#

from StdColors import black, white
from StdFonts import application_font
from Properties import Properties, overridable_property

class Canvas(Properties):

    forecolor = overridable_property('forecolor', "Foreground color.")
    backcolor = overridable_property('backcolor', "Background color.")
    pensize = overridable_property('pensize', "Width of pen for framing and stroking.")
    font = overridable_property('font', "Font for showing text.")

    def __init__(self):
        #self._init_gstack()
        self.newpath()

#    def _init_gstack(self):
#        self._gstack = []
    
    def initgraphics(self):
        self.set_forecolor(black)
        self.set_backcolor(white)
        self.set_pensize(1)
        self.set_font(application_font)
        #self.initclip()
    
    def stroke_poly(self, points):
        self._poly_path(points)
        self.stroke()

    def fill_poly(self, points):
        self._poly_path(points)
        self.fill()
    
    def _poly_path(self, points):
        self.newpath()
        point_iter = iter(points)
        self.moveto(*point_iter.next())
        for p in point_iter:
            self.lineto(*p)
        self.closepath()
    
